package com.daka.controller;

import com.daka.enumerate.StatusCode;
import com.daka.service.ActivityApplyService;
import com.daka.vo.request.ActivityVo;
import com.daka.vo.response.DataResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by yangx
 * CreateTime: 2016/9/18 15:16
 */

@Controller
@RequestMapping("/activityApply")
@Slf4j
public class ActivityApplyController {

    @Autowired
    private ActivityApplyService activityApplyService;

    @ResponseBody
    @RequestMapping(value = "/joinActivity",method = RequestMethod.POST,produces = "application/json; charset=UTF-8")
    public DataResponseVo<Object> joinActivity (@RequestBody ActivityVo vo){
        if(vo.getMemberID()==null || vo.getActivityCode()==null){
            return new DataResponseVo<Object>(StatusCode.COMMON_PARAM_ERROR.getCode(),StatusCode.COMMON_PARAM_ERROR.getMessage());
        }
        int a = activityApplyService.joinActivity(vo.getActivityCode(),vo.getMemberID());
        if(a<1){
            return new DataResponseVo<Object>(StatusCode.SERVER_EXCEPTION.getCode(), StatusCode.SERVER_EXCEPTION.getMessage());
        }
        return new DataResponseVo<Object>(StatusCode.OK.getCode(), StatusCode.OK.getMessage());
    }

    @ResponseBody
    @RequestMapping(value = "/quit",method = RequestMethod.POST,produces = "application/json; charset=UTF-8")
    public DataResponseVo<Object> quit (@RequestBody ActivityVo vo){
        if(vo.getMemberID()==null || vo.getActivityCode()==null){
            return new DataResponseVo<Object>(StatusCode.COMMON_PARAM_ERROR.getCode(),StatusCode.COMMON_PARAM_ERROR.getMessage());
        }

        int a = activityApplyService.quit(vo.getActivityCode(), vo.getMemberID());
        if(a<1){
            return new DataResponseVo<Object>(StatusCode.SERVER_EXCEPTION.getCode(), StatusCode.SERVER_EXCEPTION.getMessage());
        }
        return new DataResponseVo<Object>(StatusCode.OK.getCode(), StatusCode.OK.getMessage());
    }


}
